package day05;
import java.util.Arrays;
public class ArrayDemo {
    public static void main(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int)(Math.random()*100);
            System.out.println(arr[i]);
        }
        Arrays.sort(arr);
        System.out.println("排序后从小到大为:");
        for (int i = 0; i <arr.length ; i++) {
            System.out.println(arr[i]);
        }
        System.out.println("排序后从大到小为:");
        for (int i = arr.length-1; i >=0 ; i--) {
            System.out.println(arr[i]);
        }


        /*//1.数组的定义:
        int[] a = new int[5];               //声明整形数组a，包含5个元素，每个元素都是int类型，默认值为0
        double[] b = new double[10];        //声明浮点型数组b，包含10个元素，每个元素都是double类型，默认值为0.0
        boolean[] c = new boolean[26];      //声明布尔型数组c，包含26个元素，每个元素都是boolean类型，默认值为false

        //2.数组的初始化
        int[] arr1 = new int[3];        //0,0,0
        int[] arr2 = {2,5,8};           //2,5,8
        int[] arr3 = new int[]{2,5,8};  //2,5,8
        int[] arr4;
        arr4 = new int[]{2,5,8};        //先声明数组，在初始化数组

        //3.数组的访问
        int[] arr = new int[4];
        System.out.println(arr.length);//4
        arr[0]=2;
        arr[1]=4;
        arr[2]=6;
        arr[3]=8;
        System.out.println(arr[arr.length-1]);//8
        System.out.println(arr[0]);//2
        System.out.println(arr[1]);//4
        System.out.println(arr[2]);//6
        System.out.println(arr[3]);//8



        //4.数组的遍历(迭代)
        int arr[] = new int[10];
        for (int i = 0; i <arr.length ; i++) {
            arr[i]= (int)(Math.random()*100);
            System.out.println(arr[i]);
        }
         */

    }
}
